package com.powerhua.fms.logic.impl;

import com.powerhua.fms.dao.impl.FileDao;
import com.powerhua.fms.logic.FileManager;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.List;

public class FileManagerImpl implements FileManager {
    
    private FileDao fileDao;
    
    public void setFileDao(FileDao fileDao) {
        this.fileDao = fileDao;
    }

    public void deleteFile(File file) {
        // TODO Auto-generated method stub
    }

    public void saveFile(File file, String fileContent) {
        OutputStreamWriter out = null;
        try {
            out = new OutputStreamWriter(
                    new FileOutputStream(file), "utf-8");
            out.write(fileContent);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    public void updateFile(File file, String fileContent) {
        // TODO Auto-generated method stub
    }

    @Override
    public List listFiles(String sort, int start, int count) {
        return fileDao.getFiles(sort, start, count);
    }
}
